#pragma once
#include "zrpc/net/tcp_connection.h"
#include "zrpc/net/tcp_server.h"
#include "zrpc/rpc/rpc_channel.h"

namespace google {
namespace protobuf {
class Service;
}
}  // namespace google

namespace zrpc {
class RpcServer {
 public:
  RpcServer(EventLoop *loop, const std::string &ip, uint16_t port);
  void SetThreadNum(int num_threads) { server_.SetThreadNum(num_threads); }

  void RegisterService(::google::protobuf::Service *service);
  void Start();

 private:
  void ConnectCallback(const std::shared_ptr<TcpConnection> &conn);
  std::unordered_map<int32_t, RpcChannelPtr> rpc_channel_maps_;
  std::map<std::string, ::google::protobuf::Service *> services_;
  TcpServer server_;
};
}  // namespace zrpc